

package gui.panels.jtree.filesystem;

import gui.panels.jtree.CategoryInfo;

import java.io.*;
import java.awt.datatransfer.*;
import java.util.*;

/** This class stores all family data that we use in the example. You should
	note that no error checking is done, but you probably will want to set that up
	in your scheme especially if you are using beans! */
public class FileSystemCategoryInfo implements CategoryInfo, Transferable, Serializable {

	final public static DataFlavor INFO_FLAVOR =
		new DataFlavor(FileSystemCategoryInfo.class, "FileSystemCategoryInfo");

	static DataFlavor flavors[] = {INFO_FLAVOR };
	private String url = null;
	

	private FileSystemCategoryInfo Parent = null;
	private Vector Children = null;


	public FileSystemCategoryInfo(String url) {
		Children = new Vector();
		this.url = url;

	}

	public String getName() {
		File aux = new File(url);
		return aux.getName();
	}

	public void setName(String name) {
		//TODO 
	}






	public void add(CategoryInfo info) {
		info.setParent(this);
		Children.add(info);
	}

	public void remove(CategoryInfo info) {
		info.setParent(null);
		Children.remove(info);
	}

	public CategoryInfo getParent() {
		return Parent;
	}

	public void setParent(CategoryInfo parent) {
		Parent = (FileSystemCategoryInfo) parent;
	}

	public Vector getChildren() {
		return Children;
	}



	public String toString() {
		File aux = new File(url);
		return aux.getName();
	}

	// --------- Transferable --------------

	public boolean isDataFlavorSupported(DataFlavor df) {
		return df.equals(INFO_FLAVOR);
	}

	/** implements Transferable interface */
	public Object getTransferData(DataFlavor df)
	throws UnsupportedFlavorException, IOException {
		if (df.equals(INFO_FLAVOR)) {
			return this;
		}
		else throw new UnsupportedFlavorException(df);
	}

	/** implements Transferable interface */
	public DataFlavor[] getTransferDataFlavors() {
		return flavors;
	}

	// --------- Serializable --------------

	private void writeObject(java.io.ObjectOutputStream out) throws IOException {
		out.defaultWriteObject();
	}

	private void readObject(java.io.ObjectInputStream in)
	throws IOException, ClassNotFoundException {
		in.defaultReadObject();
	}

	
	public DataFlavor getDataFlavor() {
		
		return FileSystemCategoryInfo.INFO_FLAVOR;
	}

	@Override
	public String getURL() {
		
		return url;
	}

	@Override
	public void setURL(String url) {
	
		this.url=url;
	}
}



